package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.bean.wx.vo.WxUserIndexOrderVO;
import com.cskaoyan.service.OrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author tangjian
 * @Date 2021/10/21 15:50
 * @description
 */
@RestController
@RequestMapping("/wx/user")
public class WxUserController {

    @Autowired
    OrderService orderService;

    @RequestMapping("/index")
    public BaseRespVo userIndex(){

        WxUserIndexOrderVO wxUserIndexOrderVO = new WxUserIndexOrderVO();
        WxUserIndexOrderVO.Order order = wxUserIndexOrderVO.getOrder();

        Integer userId;
        Subject subject = SecurityUtils.getSubject();
        User user = (User) subject.getPrincipal();
        try {
            userId = user.getId();
        }catch (Exception e){
            return BaseRespVo.ok(wxUserIndexOrderVO);
        }



        Integer uncomment = orderService.countUncommentByUserId(userId);
        Integer unpaid = orderService.countUnpaidByUserId(userId);//101
        Integer unship = orderService.countUnshipByUserId(userId);//201
        Integer unrecv = orderService.countUnrecvByUserId(userId);//301

        order.setUncomment(uncomment);
        order.setUnpaid(unpaid);
        order.setUnrecv(unrecv);
        order.setUnship(unship);

        return BaseRespVo.ok(wxUserIndexOrderVO);
    }
}
